#ifndef _CPHYSICSMAIN_H_20120105__
#define _CPHYSICSMAIN_H_20120105__

#include <list>
#include <btBulletDynamicsCommon.h>
#include "../Objects/CLivingObject.h"
#include <time.h>

class CPhysicsMain
{
public:
    CPhysicsMain();
    ~CPhysicsMain();

    /**
        Does the basic setup of bullet to be able to do anything
    */
    void setupPhysicsWorld();

    /**
      Destroys all pointers and stuff to clean up.
      After this point Everything has to be setup again!
      */
    void destroyPhysicsWorld();

    /**
      Starts the physics cycle in a seperate thread, so the graphics and physics run asyncron
      TODO: Check if this is a good idea and implement
      */
    void startPhysicsCycle();

    /**
      Setps through the physics world.
      Is called by the graphics engine, after one frame has been rendered.
      Updates all object positions, so the graphics and physics world are synchronised again.
      */
    void advanceOneStep(double timeSinceLastCallInSeconds);

    /**
      Adds an object to the physics world
      */
    void addObject(BaseObject* object);

    /**
      Removes an object from the physics world
      */
    void removeObject(BaseObject* object);

    /**
      creates a new physics object. Actually it fills the parameters of the BaseObject and can be added to the world by
      using addObject() and removeObject()
      */
    void prepareObject(BaseObject* object);

private:
    btBroadphaseInterface* m_broadphase;
    btDefaultCollisionConfiguration* m_collisionConfiguration;
    btCollisionDispatcher* m_dispatcher;
    btSequentialImpulseConstraintSolver* m_solver;
    btDiscreteDynamicsWorld* m_dynamicsWorld;

};


#endif //_CPHYSICSMAIN_H_20120105__
